/**
 * Created on Sat Mar 12 15:20:50 CST 2011
 * Copyright SinoBest, 2010-2011, All rights reserved.
 */package cn.com.test.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.test.dao.Reply;


/**
 * @Author zhou
 * @Date Sat Mar 12 15:20:50 CST 2011
 * @to-do 
 */public class ReplyDAO extends HibernateDaoSupport {
	
	private static final Log log = LogFactory.getLog(ReplyDAO.class);
	
	// property constants
	public static final String SYSTEMID = "systemid";
	public static final String PROBLEMID = "problemid";
	public static final String REPLY = "reply";
	public static final String CREATOR = "creator";
	public static final String CREATETIME = "createtime";
	
	// property constants
	protected void initDao() {
		// do nothing
	}
	
	public void save(Reply transientInstance) {
		log.debug("saving Reply instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(Reply persistentInstance) {
		log.debug("deleting Reply instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public Reply findById(java.lang.String id) {
		log.debug("getting Reply instance with id: " + id);
		try {
			Reply instance = (Reply) getHibernateTemplate().get(
					"cn.com.test.dao.Reply", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findAll() {
		log.debug("finding all Reply instances");
		try {
			String queryString = "from Reply";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public Reply merge(Reply detachedInstance) {
		log.debug("merging Reply instance");
		try {
			Reply result = (Reply) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public void attachDirty(Reply instance) {
		log.debug("attaching dirty Reply instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Reply instance) {
		log.debug("attaching clean Reply instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ReplyDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ReplyDAO) ctx.getBean("ReplyDAO");
	}
	
	public List findByExample(Reply instance) {
		log.debug("finding Reply instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Reply instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Reply as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findBySystemid(Object systemid) {
		return findByProperty(SYSTEMID, systemid);
	}
	public List findByProblemid(Object problemid) {
		return findByProperty(PROBLEMID, problemid);
	}
	public List findByReply(Object reply) {
		return findByProperty(REPLY, reply);
	}
	public List findByCreator(Object creator) {
		return findByProperty(CREATOR, creator);
	}
	public List findByCreatetime(Object createtime) {
		return findByProperty(CREATETIME, createtime);
	}

}